/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShAdsDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShAdsService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShAds;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShAdsService 实现类
 * @author KongXiangyu
 * @since 2015-11-23
 */
@Service("shAdsService")
public class ShAdsServiceImpl extends BaseServiceImpl<ShAds, Long> implements ShAdsService {

    @Resource
    private ShAdsDao shAdsDao;

    public BaseDao<ShAds, Long> getDao() {
        return shAdsDao;
    }

	/* (non-Javadoc)
	 * @see com.smarthome.base.service.ShAdsService#selectDatagrid(com.smarthome.domain.bean.ShAds, com.smarthome.domain.vo.boss.PageHelper)
	 */
	@Override
	public DataGrid selectDatagrid(ShAds ads, PageHelper page) {
		DataGrid dataGrid = new DataGrid();
        long totalCount = shAdsDao.selectEntryListCount(ads);
        dataGrid.setTotal(totalCount);
        int startIndex = (page.getPage() - 1) * page.getRows();
        int endIndex = page.getPage() * page.getRows();
        if (totalCount > 0 && totalCount > startIndex) {
        	ads.setStartIndex(startIndex);
        	ads.setEndIndex(endIndex);
        	ads.setOrderField(page.getSort());
        	ads.setOrderFieldType(page.getOrder());
            List<ShAds> adss = shAdsDao.selectEntryList(ads);
            dataGrid.setRows(adss);
        }
        return dataGrid;
	}

}